clear all
set more off

****************************************
* FIGURE 1 - OAXACA-BLINDER 
****************************************
use "${file}sine_panel.dta", clear
set matsize 5000

tabulate YEAR, generate(YEAR_) nofreq
egen naf4=group(NAF4)
tabulate naf4, generate(NAF4_) nofreq // gen dummies sectors
egen MOYENS6Ag=group(MOYENS6A)
tabulate MOYENS6Ag, generate(MOYENS_) nofreq // gen dummies initial capital buckets

****
* All SECTORS (APPENDIX FIGURE)
****

preserve
set more off
oaxaca FINV4 nf4crea AGED NATIOA1 EDUC2 EDUC3 GRANDEECO EXPERT SERIAL DIRIGA INC INOV_SUM OBJECTIF ///
MOTIV1 MOTIV2 MOTIV4 MOTIV3 MOTIV5 ///
B2B GEOCLIA NBCLIA3 NBCLIA4 ///
MOYENS_4 MOYENS_5 MOYENS_6 MOYENS_7 MOYENS_8 ///
FINV1 FINV2 FINV3 FINV5 ///
NAF4_* ///
, by(FEMALE) pooled d relax swap ///
detail(fi: FINV1 FINV2 FINV3 FINV5 FINV6, ///
fam: ENF COUPL, ///
sector: NAF4_*, ///
fsector: nf4crea, ///
)

mat list e(b)  

gen number=_n
gen variable_1=.
gen variable_2=.
gen label=""

replace variable_1=[explained]_b[AGED] if number==1
replace variable_2=[unexplained]_b[AGED] if number==1
replace label="Age>40" if number==1

replace variable_1=[explained]_b[GRANDEECO] if number==2
replace variable_2=[unexplained]_b[GRANDEECO] if number==2
replace label="Elite school" if number==2

replace variable_1=[explained]_b[EXPERT] if number==3
replace variable_2=[unexplained]_b[EXPERT] if number==3
replace label="Industry expert" if number==3

replace variable_1=[explained]_b[SERIAL] if number==4
replace variable_2=[unexplained]_b[SERIAL] if number==4
replace label="Serial entrepeneur" if number==4

replace variable_1=[explained]_b[DIRIGA] if number==5
replace variable_2=[unexplained]_b[DIRIGA] if number==5
replace label="Co-founders" if number==5

replace variable_1=[explained]_b[INC] if number==6
replace variable_2=[unexplained]_b[INC] if number==6
replace label="Incorporated" if number==6

replace variable_1=[explained]_b[INOV_SUM] if number==7
replace variable_2=[unexplained]_b[INOV_SUM] if number==7
replace label="Innovative" if number==7

replace variable_1=[explained]_b[OBJECTIF] if number==20
replace variable_2=[unexplained]_b[OBJECTIF] if number==20
replace label="Growth-oriented"  if number==20

replace variable_1=[explained]_b[MOTIV2] if number==26
replace variable_2=[unexplained]_b[MOTIV2] if number==26
replace label="Motiv: Taste" if number==26

replace variable_1=[explained]_b[MOTIV4] if number==21
replace variable_2=[unexplained]_b[MOTIV4] if number==21
replace label="Motiv: Opportunity" if number==21

replace variable_1=[explained]_b[MOTIV1] if number==23
replace variable_2=[unexplained]_b[MOTIV1] if number==23
replace label="Motiv: Independence" if number==23

replace variable_1=[explained]_b[MOTIV3] if number==24
replace variable_2=[unexplained]_b[MOTIV3] if number==24
replace label="Motiv: New idea" if number==24

replace variable_1=[explained]_b[MOTIV5] if number==25
replace variable_2=[unexplained]_b[MOTIV5] if number==25
replace label="Motiv: Peers" if number==25

replace variable_1=[overall]_b[explained] if number==70
replace variable_2=[overall]_b[unexplained] if number==70
replace label="Total" if number==70

drop if variable_1==.
keep number variable_1 variable_2 label
duplicates drop
gen group=1 if number<68
replace group=number if number>68
gen sumabs=abs(variable_1)+abs(variable_2)
sort group sumabs
gen number2=_n 
replace number2=0 if label=="Age + Citizenship"

gr bar variable_1 variable_2, over(label, sort(number) label(angle(45))) ///
stack graphregion(color(white))  title("All Sectors", size(medsmall))  ///
legend(label(1 "Explained effect") label(2 "Unexplained effect")) ytitle(Covariates coefficients) ///
ysc(r(-0.014 0 0.006) ) ylabel(-0.014(0.002)0.006, labsize(vsmall)) legend(region(lcolor(white))) ///
bar(1, color(blue*2.5)) bar(2, color(orange_red)) blabel(total, position(ouside) format(%9.4f) size(vsmall)) 
graph export "${output}/graph_oaxaca.eps", replace
restore


**************************************
* FIGURE 1 - FEMALE-DOMINATED SECTORS
**************************************
preserve
set more off

oaxaca FINV4 AGED NATIOA1 EDUC2 EDUC3 GRANDEECO EXPERT SERIAL DIRIGA INC INOV_SUM OBJECTIF ///
MOTIV1 MOTIV2 MOTIV4 MOTIV3 MOTIV5 ///
B2B GEOCLIA NBCLIA3 NBCLIA4 ///
MOYENS_4 MOYENS_5 MOYENS_6 MOYENS_7 MOYENS_8 ///
FINV1 FINV2 FINV3 FINV5 ///
NAF4_* ///
if NAF4_crea_d5==1, by(FEMALE) pooled d relax swap ///
detail(fi: FINV1 FINV2 FINV3 FINV5 FINV6, ///
fam: ENF COUPL PROCHA, ///
sector: NAF4_*, ///
fsector: nf4crea, ///
capital: MOYENS_4 MOYENS_5 MOYENS_6 MOYENS_7 MOYENS_8, ///
)

mat list e(b)  

gen number=_n
gen variable_1=.
gen variable_2=.
gen label=""

replace variable_1=[explained]_b[AGED] if number==1
replace variable_2=[unexplained]_b[AGED] if number==1
replace label="Age>40" if number==1

replace variable_1=[explained]_b[GRANDEECO] if number==2
replace variable_2=[unexplained]_b[GRANDEECO] if number==2
replace label="Elite school" if number==2

replace variable_1=[explained]_b[EXPERT] if number==3
replace variable_2=[unexplained]_b[EXPERT] if number==3
replace label="Industry expert" if number==3

replace variable_1=[explained]_b[SERIAL] if number==4
replace variable_2=[unexplained]_b[SERIAL] if number==4
replace label="Serial entrepeneur" if number==4

replace variable_1=[explained]_b[DIRIGA] if number==5
replace variable_2=[unexplained]_b[DIRIGA] if number==5
replace label="Co-founders" if number==5

replace variable_1=[explained]_b[INC] if number==6
replace variable_2=[unexplained]_b[INC] if number==6
replace label="Incorporated" if number==6

replace variable_1=[explained]_b[INOV_SUM] if number==7
replace variable_2=[unexplained]_b[INOV_SUM] if number==7
replace label="Innovative" if number==7

replace variable_1=[explained]_b[capital] if number==10
replace variable_2=[unexplained]_b[capital] if number==10
replace label="Startup capital" if number==10

replace variable_1=[explained]_b[OBJECTIF] if number==20
replace variable_2=[unexplained]_b[OBJECTIF] if number==20
replace label="Growth-oriented"  if number==20

replace variable_1=[explained]_b[MOTIV4] if number==21
replace variable_2=[unexplained]_b[MOTIV4] if number==21
replace label="Motiv: Opportunity" if number==21

replace variable_1=[explained]_b[MOTIV1] if number==23
replace variable_2=[unexplained]_b[MOTIV1] if number==23
replace label="Motiv: Independence" if number==23

replace variable_1=[explained]_b[MOTIV3] if number==24
replace variable_2=[unexplained]_b[MOTIV3] if number==24
replace label="Motiv: New idea" if number==24

replace variable_1=[explained]_b[MOTIV5] if number==25
replace variable_2=[unexplained]_b[MOTIV5] if number==25
replace label="Motiv: Peers" if number==25

replace variable_1=[explained]_b[MOTIV2] if number==26
replace variable_2=[unexplained]_b[MOTIV2] if number==26
replace label="Motiv: Taste" if number==26

replace variable_1=[overall]_b[explained] if number==70
replace variable_2=[overall]_b[unexplained] if number==70
replace label="Total" if number==70

drop if variable_1==.
keep number variable_1 variable_2 label
duplicates drop
gen group=1 if number<68
replace group=number if number>68
gen sumabs=abs(variable_1)+abs(variable_2)
sort group sumabs
gen number2=_n 
replace number2=0 if label=="Age + Citizenship"

 gr bar variable_1 variable_2, over(label, sort(number) label(angle(45))) ///
 stack graphregion(color(white))  title("Female-dominated Sectors", size(medsmall))  ///
 legend(label(1 "Explained effect") label(2 "Unexplained effect")) ytitle(Covariates coefficients) ///
 ysc(r(-0.014 0 0.006) ) ylabel(-0.014(0.002)0.006, labsize(vsmall)) legend(region(lcolor(white))) ///
 bar(1, color(blue*2.5)) bar(2, color(orange_red)) blabel(total, position(ouside) format(%9.4f) size(vsmall)) 
 
graph export "${output}/graph_oaxaca_fsec.pdf", replace
graph export "${output}/graph_oaxaca_fsec.eps", replace
restore


**************************************
* FIGURE 1 - MALE-DOMINATED SECTORS
**************************************
preserve
set more off
oaxaca FINV4 AGED NATIOA1 EDUC2 EDUC3 GRANDEECO EXPERT SERIAL DIRIGA INC INOV_SUM OBJECTIF ///
MOTIV1 MOTIV2 MOTIV4 MOTIV3 MOTIV5 ///
B2B GEOCLIA NBCLIA3 NBCLIA4 ///
MOYENS_4 MOYENS_5 MOYENS_6 MOYENS_7 MOYENS_8 ///
FINV1 FINV2 FINV3 FINV5 ///
NAF4_* ///
if NAF4_crea_d5==0, by(FEMALE) pooled d relax swap ///
detail(fi: FINV1 FINV2 FINV3 FINV5 FINV6, ///
fam: ENF COUPL PROCHA, ///
sector: NAF4_*, ///
fsector: nf4crea, ///
capital: MOYENS_4 MOYENS_5 MOYENS_6 MOYENS_7 MOYENS_8, ///
)

mat list e(b)  

gen number=_n
gen variable_1=.
gen variable_2=.
gen label=""

replace variable_1=[explained]_b[AGED] if number==1
replace variable_2=[unexplained]_b[AGED] if number==1
replace label="Age>40" if number==1

replace variable_1=[explained]_b[GRANDEECO] if number==2
replace variable_2=[unexplained]_b[GRANDEECO] if number==2
replace label="Elite school" if number==2

replace variable_1=[explained]_b[EXPERT] if number==3
replace variable_2=[unexplained]_b[EXPERT] if number==3
replace label="Industry expert" if number==3

replace variable_1=[explained]_b[SERIAL] if number==4
replace variable_2=[unexplained]_b[SERIAL] if number==4
replace label="Serial entrepeneur" if number==4

replace variable_1=[explained]_b[DIRIGA] if number==5
replace variable_2=[unexplained]_b[DIRIGA] if number==5
replace label="Co-founders" if number==5

replace variable_1=[explained]_b[INC] if number==6
replace variable_2=[unexplained]_b[INC] if number==6
replace label="Incorporated" if number==6

replace variable_1=[explained]_b[INOV_SUM] if number==7
replace variable_2=[unexplained]_b[INOV_SUM] if number==7
replace label="Innovative" if number==7

replace variable_1=[explained]_b[capital] if number==10
replace variable_2=[unexplained]_b[capital] if number==10
replace label="Startup capital" if number==10

replace variable_1=[explained]_b[OBJECTIF] if number==20
replace variable_2=[unexplained]_b[OBJECTIF] if number==20
replace label="Growth-oriented" if number==20

replace variable_1=[explained]_b[MOTIV4] if number==21
replace variable_2=[unexplained]_b[MOTIV4] if number==21
replace label="Motiv: Opportunity" if number==21

replace variable_1=[explained]_b[MOTIV1] if number==23
replace variable_2=[unexplained]_b[MOTIV1] if number==23
replace label="Motiv: Independence" if number==23

replace variable_1=[explained]_b[MOTIV3] if number==24
replace variable_2=[unexplained]_b[MOTIV3] if number==24
replace label="Motiv: New idea" if number==24

replace variable_1=[explained]_b[MOTIV5] if number==25
replace variable_2=[unexplained]_b[MOTIV5] if number==25
replace label="Motiv: Peers" if number==25

replace variable_1=[explained]_b[MOTIV2] if number==26
replace variable_2=[unexplained]_b[MOTIV2] if number==26
replace label="Motiv: Taste" if number==26

replace variable_1=[overall]_b[explained] if number==70
replace variable_2=[overall]_b[unexplained] if number==70
replace label="Total" if number==70

drop if variable_1==.
keep number variable_1 variable_2 label
duplicates drop
gen group=1 if number<68
replace group=number if number>68
gen sumabs=abs(variable_1)+abs(variable_2)
sort group sumabs
gen number2=_n 
replace number2=0 if label=="Age + Citizenship"

 gr bar variable_1 variable_2, over(label, sort(number) label(angle(45))) ///
 stack graphregion(color(white))  title("Male-dominated Sectors", size(medsmall))  ///
 legend(label(1 "Explained effect") label(2 "Unexplained effect")) ytitle(Covariates coefficients) ///
 ysc(r(-0.010 0 0.002) ) ylabel(-0.010(0.002)0.002, labsize(vsmall)) legend(region(lcolor(white))) ///
 bar(1, color(blue*2.5)) bar(2, color(orange_red)) blabel(total, position(ouside) format(%9.4f) size(vsmall)) 
 
graph export "${output}/graph_oaxaca_msec.pdf", replace
graph export "${output}/graph_oaxaca_msec.eps", replace
restore


*****************************************
* APPENDIX TABLE - OAXACA-BLINDER TABLE
*****************************************
eststo clear
set more off

* all with sector fe
oaxaca FINV4 nf4crea AGED NATIOA1 EDUC2 EDUC3 GRANDEECO EXPERT SERIAL DIRIGA INC INOV_SUM OBJECTIF ///
MOTIV1 MOTIV2 MOTIV4 MOTIV3 MOTIV5 ///
B2B GEOCLIA NBCLIA3 NBCLIA4 ///
MOYENS_4 MOYENS_5 MOYENS_6 MOYENS_7 MOYENS_8 ///
FINV1 FINV2 FINV3 FINV5 ///
NAF4_* ///
, by(FEMALE) pooled d relax swap ///
detail(bio: AGED , ///
educ: GRANDEECO, ///
exp: EXPERT , ///
seri: SERIAL , ///
team: DIRIGA , ///
inov: INOV_SUM , ///
capital: MOYENS_1 MOYENS_2 MOYENS_3 MOYENS_4 MOYENS_5 MOYENS_6 MOYENS_7 MOYENS_8, ///
bm: B2B GEOCLIA GEOCLIA2 GEOCLIA3 GEOCLIA1 NBCLIA1 NBCLIA2 NBCLIA3 NBCLIA4, ///
obj: OBJECTIF, ///
fi: FINV1 FINV2 FINV3 FINV5 FINV6, ///
sector: NAF4_*, ///
fsector: nf4crea, ///
)
mat list e(b)  
estimates store oax
estout oax, cells(b)
gen sampleoax=e(sample)

* all without sector fe
oaxaca FINV4 nf4crea AGED NATIOA1 EDUC2 EDUC3 GRANDEECO EXPERT SERIAL DIRIGA INC INOV_SUM OBJECTIF ///
MOTIV1 MOTIV2 MOTIV4 MOTIV3 MOTIV5 ///
B2B GEOCLIA NBCLIA3 NBCLIA4 ///
MOYENS_4 MOYENS_5 MOYENS_6 MOYENS_7 MOYENS_8 ///
FINV1 FINV2 FINV3 FINV5 ///
, by(FEMALE) pooled d relax swap ///
detail(bio: AGED , ///
educ: GRANDEECO, ///
exp: EXPERT , ///
seri: SERIAL , ///
team: DIRIGA , ///
inov: INOV_SUM , ///
capital: MOYENS_1 MOYENS_2 MOYENS_3 MOYENS_4 MOYENS_5 MOYENS_6 MOYENS_7 MOYENS_8, ///
bm: B2B GEOCLIA GEOCLIA2 GEOCLIA3 GEOCLIA1 NBCLIA1 NBCLIA2 NBCLIA3 NBCLIA4, ///
obj: OBJECTIF, ///
fi: FINV1 FINV2 FINV3 FINV5 FINV6, ///
sector: NAF4_*, ///
fsector: nf4crea, ///
)
mat list e(b)  
estimates store oax_w
estout oax, cells(b)

* male-dominated sectors
oaxaca FINV4 nf4crea AGED NATIOA1 EDUC2 EDUC3 GRANDEECO EXPERT SERIAL DIRIGA INC INOV_SUM OBJECTIF ///
MOTIV1 MOTIV2 MOTIV4 MOTIV3 MOTIV5 ///
B2B GEOCLIA NBCLIA3 NBCLIA4 ///
MOYENS_4 MOYENS_5 MOYENS_6 MOYENS_7 MOYENS_8 ///
FINV1 FINV2 FINV3 FINV5 ///
NAF4_* ///
if NAF4_crea_d5==0, by(FEMALE) pooled d relax swap ///
detail(bio: AGED , ///
educ: GRANDEECO, ///
exp: EXPERT , ///
seri: SERIAL , ///
team: DIRIGA , ///
inov: INOV_SUM , ///
capital: MOYENS_1 MOYENS_2 MOYENS_3 MOYENS_4 MOYENS_5 MOYENS_6 MOYENS_7 MOYENS_8, ///
bm: B2B GEOCLIA GEOCLIA2 GEOCLIA3 GEOCLIA1 NBCLIA1 NBCLIA2 NBCLIA3 NBCLIA4, ///
obj: OBJECTIF, ///
fi: FINV1 FINV2 FINV3 FINV5 FINV6, ///
sector: NAF4_*, ///
fsector: nf4crea, ///
)
mat list e(b)  
estimates store oax_msec
estout oax, cells(b)


* female-dominated secors
oaxaca FINV4 nf4crea AGED NATIOA1 EDUC2 EDUC3 GRANDEECO EXPERT SERIAL DIRIGA INC INOV_SUM OBJECTIF ///
MOTIV1 MOTIV2 MOTIV4 MOTIV3 MOTIV5 ///
B2B GEOCLIA NBCLIA3 NBCLIA4 ///
MOYENS_4 MOYENS_5 MOYENS_6 MOYENS_7 MOYENS_8 ///
FINV1 FINV2 FINV3 FINV5 ///
NAF4_* ///
if NAF4_crea_d5==1, by(FEMALE) pooled d relax swap ///
detail(bio: AGED , ///
educ: GRANDEECO, ///
exp: EXPERT , ///
seri: SERIAL , ///
team: DIRIGA , ///
inov: INOV_SUM , ///
capital: MOYENS_1 MOYENS_2 MOYENS_3 MOYENS_4 MOYENS_5 MOYENS_6 MOYENS_7 MOYENS_8, ///
bm: B2B GEOCLIA GEOCLIA2 GEOCLIA3 GEOCLIA1 NBCLIA1 NBCLIA2 NBCLIA3 NBCLIA4, ///
obj: OBJECTIF, ///
fi: FINV1 FINV2 FINV3 FINV5 FINV6, ///
sector: NAF4_*, ///
fsector: nf4crea, ///
)
mat list e(b)  
estimates store oax_fsec
estout oax, cells(b)


esttab oax oax_w oax_msec oax_fsec  /*
*/ using "${output}table_oaxaca_test.csv" /*
*/ ,replace csv label lines compress nocons collabels(none) nodepvars nomtitles nonumber fragment /*
*/ cells("b(star fmt(%9.4f))") star(* 0.10 ** 0.05 *** 0.01) /*
*/ stats(N N_1 N_2 , fmt(0 0 0) /*
*/ labels( `"N"' `"N Male"'  `"N Female"')) /*
*/ keep(group_1 group_2 difference explained unexplained /*
*/ bio educ exp seri team inov obj bm capital fi fsector MOTIV1 MOTIV2 MOTIV4 MOTIV3 MOTIV5) /*
*/ order(group_1 group_2 difference explained unexplained /*
*/ bio educ exp seri team inov obj MOTIV1 MOTIV2 MOTIV4 MOTIV3 MOTIV5 capital fi fsector sector )

